package JAVA300.第七章数组;

public class TestArrayCopy {
    public static void main(String[] args) {
        //TestBasicCopy();
        String[] s1 = {"1","2","3"};
        extendArray(s1);
    }
//arraycopy
    public static void TestBasicCopy(){
        String[] str1 = {"aa","bb","cc","dd"};
        String[] str2 = new String[10];
        String[] str3 = new String[4] ;

        System.arraycopy(str1,2,str2,4,2);
        System.arraycopy(str1,2,str1,2-1,str1.length-2);//用来进行数组剪切

//        for (int i=0;i<str2.length;i++){
//            System.out.println(i+"--"+str2[i]);
//        }

        for (int i=0;i<str1.length;i++){
            System.out.println(i+"--"+str1[i]);
        }
    }
//数组扩容
    public static String[] extendArray(String[] s1){
      //  String[] s1 = {"1","2","3"};
        String[] s2 = new String[s1.length+5];

        System.arraycopy(s1,0,s2,0,s1.length);

        for(String temp:s2){
            System.out.println(temp);
        }

        return s2;
    }
}
